//
//  PhotoListViewCell.m
//  SecretAlbums
//
//  Created by Tinys on 15/6/20.
//  Copyright (c) 2015年 BabyFinancial. All rights reserved.
//

#import "ThumbnailCell.h"
#import "NSDateFormatter+timeIntervalFormatter.h"
#import "UIImage+CTAssetsPickerController.h"
#import "SecretAlbumsPersistence.h"
#import "SecretAlbumsLogic.h"
#import "ThumbnailCellMask.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface ThumbnailCell ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) ThumbnailCellMask *thumbnailCellMask;

@end

@implementation ThumbnailCell

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor blackColor];
        
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self addSubview:self.imageView];
        
        self.thumbnailCellMask = [[ThumbnailCellMask alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self addSubview:self.thumbnailCellMask];
    }
    
    return self;
}

- (void)bind:(Media *)media
{
    NSURL *url = [NSURL fileURLWithPath:[SecretAlbumsLogic pathWithMediaType:MediaTypeThumbnail name:media.fileName]];
    [self.imageView sd_setImageWithURL:url];
    
    self.thumbnailCellMask.isVideo = media.isVideo.boolValue;
    self.thumbnailCellMask.title = media.propertyDuration;
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    
    self.thumbnailCellMask.isSelected = selected;
    [self.thumbnailCellMask setNeedsDisplay];
}

@end
